package com.bnd.domain.session;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.audio.asr.recognition.Recognition;
import com.alibaba.dashscope.audio.asr.recognition.RecognitionParam;
import com.alibaba.dashscope.audio.asr.recognition.RecognitionResult;
import com.alibaba.dashscope.audio.tts.SpeechSynthesisResult;
import com.alibaba.dashscope.audio.ttsv2.SpeechSynthesisParam;
import com.alibaba.dashscope.audio.ttsv2.SpeechSynthesizer;
import com.alibaba.dashscope.common.ResultCallback;
import jakarta.websocket.Session;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.nio.ByteBuffer;

@EqualsAndHashCode(callSuper = true)
@Data
public class WsChatSession extends BaseChatSession{

    /**
     * 语音合成缓冲区
     */
    private ByteBuffer ttsByteBuffer;

    /**
     * 语音识别缓冲区
     */
    private ByteBuffer asrByteBuffer;

    /**
     * 语音识别客户端
     */
    private Recognition recognition;

    /**
     * 语音合成客户端
     */
    private SpeechSynthesizer speechSynthesizer;

    /**
     * 语音识别参数
     */
    private RecognitionParam recognitionParam;

    /**
     * 语音合成参数
     */
    private SpeechSynthesisParam speechSynthesisParam;

    /**
     * 语音合成回调
     */
    private ResultCallback<SpeechSynthesisResult> ttsCallback;

    /**
     * 语音识别
     */
    private ResultCallback<RecognitionResult> asrCallback;

    /**
     * 对话客户端
     */
    private Generation generation;

    public WsChatSession(String chatId, Long characterId, Session session) {
        this.chatId = chatId;
        this.session = session;
        this.characterId = characterId;
        this.messageList = CollectionUtil.newArrayList();
        this.ttsByteBuffer = ByteBuffer.allocate(4 * 1024);
        this.asrByteBuffer = ByteBuffer.allocate(2 * 1024);
        this.recognition = new Recognition();
        this.generation = new Generation();
    }
}
